package com.jinzhi.jzweb.service.impl;

import cn.afterturn.easypoi.word.WordExportUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.base.CoreServiceImpl;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.certificate.pojo.MyResultsVo;
import com.jinzhi.jzweb.controller.yyrby.ScResultVO;
import com.jinzhi.jzweb.dao.ExaminationResultsComDao;
import com.jinzhi.jzweb.domain.ExaminationResultsComDO;
import com.jinzhi.jzweb.domain.moduleConfig.CareStuSignUpComRealityDO;
import com.jinzhi.jzweb.pojo.*;
import com.jinzhi.jzweb.pojo.moduleConfig.*;
import com.jinzhi.jzweb.service.ExaminationResultsComService;
import com.jinzhi.jzweb.service.moduleConfig.CareStuSignUpComRealityService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import com.jinzhi.jzweb.utils.PageLogicalUtil;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 
 * <pre>
 * 考试   成绩
 * </pre>
 * <small> 2020-02-24 21:00:12 | lance</small>
 */
@Service
public class ExaminationResultsComServiceImpl extends CoreServiceImpl<ExaminationResultsComDao, ExaminationResultsComDO> implements ExaminationResultsComService {

    @Autowired
    private CareStuSignUpComRealityService careStuSignUpComRealityService;

    @Autowired
    private  ExaminationResultsComService examinationResultsComService;

    @Override
    public Page<MyResultsVo> selByUserId(Map map,int current, int number) {

        // 新建分页
        Page<MyResultsVo> page = new Page<MyResultsVo>(current, number);

        return page.setRecords(this.baseMapper.selByUserId(page,map));
    }

    @Override
    public Page<ExaminationResultsComDO> findLists(Map map,int current , int number) {
        Page<ExaminationResultsComDO> page = new Page<ExaminationResultsComDO>(current, number);

        return page.setRecords(this.baseMapper.findLists(page,map));
    }

    @Override
    public Page<ExaminationResultsComDO> findPageList(Map map, int current, int number) {

        Page<ExaminationResultsComDO> page = new Page<ExaminationResultsComDO>(current, number);

        return page.setRecords(this.baseMapper.findPageList(page,map));
    }

    @Override
    public Page<ExaminationResultsComDO> findList(Map map, int current, int number) {

        Page<ExaminationResultsComDO> page = new Page<ExaminationResultsComDO>(current, number);

        return page.setRecords(this.baseMapper.findList(page,map));
    }

	@Override
	public List<ExaminationResultsExportVo> exportList(Map map) {
		
		return this.baseMapper.exportList(map);
	}

    @Override
    public List<ExaminationResultsExportAllVo> exportListAll(Map map) {
        return this.baseMapper.exportListAll(map);
    }

    @Override
    public List<ExaminationResultsPoVo> resultList(Long ebatchId) {
        return baseMapper.resultList(ebatchId);
    }

    @Override
    public List<ExaminationResultsABCPoVo> listABC() {
        return this.baseMapper.listABC();
    }


    /**
     * 制定照护计划分数统计
     * @return
     */
    @Override
    public Page<ExaminationResultsPoVo> zhiDingStatistics(ExaminationResultsComDO examinationResultsComDO) {
        Map map =new HashMap();
        map.put("field","A");
        Page<ExaminationResultsPoVo> page = new Page<>(examinationResultsComDO.getPageNumber(), examinationResultsComDO.getPageSize());//分页
        List<ExaminationResultsPoVo> pageList = new ArrayList<>();
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);

        examinationResultsPoVos.stream()
                .sorted(Comparator.comparing(ExaminationResultsPoVo::getLlCqNumber,Comparator.naturalOrder()))
                .collect(Collectors.toList());

        if(null!=examinationResultsPoVos && !examinationResultsPoVos.isEmpty()){
            Map<String, List<ExaminationResultsPoVo>> groupedMap = examinationResultsPoVos.stream()
                    .collect(Collectors.groupingBy(ExaminationResultsPoVo::getUnitName));
            for (Map.Entry<String, List<ExaminationResultsPoVo>> entry : groupedMap.entrySet()){
                List<ExaminationResultsPoVo> valueList = entry.getValue();
                //计算裁判平均分
                for (ExaminationResultsPoVo examinationResultsPoVo : valueList) {
                    //计算裁判打分平均分和最终得分
                    getAvgZhiDing(examinationResultsPoVo);
                    Wrapper<ExaminationResultsComDO> jkWrapper =  new EntityWrapper<ExaminationResultsComDO>();
                    jkWrapper.eq("field","C");
                    jkWrapper.eq("num2",examinationResultsPoVo.getNum2());
                    List<ExaminationResultsComDO> examinationResultsComDOS = examinationResultsComService.selectList(jkWrapper);
                    if (examinationResultsComDOS.size()>0){
                        ExaminationResultsComDO exr =  examinationResultsComDOS.get(0);
                        examinationResultsPoVo.setJkScore(String.valueOf(exr.getTotalScore())); //机考成绩
                        examinationResultsPoVo.setScAverageScore(String.valueOf(Double.valueOf(examinationResultsPoVo.getAverageScore()) + Double.valueOf(examinationResultsPoVo.getJkScore()))); //赛场得分
                    }
                }
                //考虑一名选手的情况
                if(valueList.size()==1){
                    //判断是否已经解密
                    ExaminationResultsPoVo examinationResultsPoVo = new ExaminationResultsPoVo();
                    if(valueList.get(0).getDecrypt()==0){
                        examinationResultsPoVo.setDecrypt(0);
                        valueList = new ArrayList<>();
                        valueList.add(examinationResultsPoVo);
                        valueList.add(examinationResultsPoVo);
                    } else {
                        ExaminationResultsCopyPoVo examinationResultsCopyPoVo = new ExaminationResultsCopyPoVo();
                        BeanUtils.copyProperties(examinationResultsCopyPoVo,examinationResultsPoVo);
                        examinationResultsPoVo.setDecrypt(1);
                        examinationResultsPoVo.setRecordNumber(valueList.get(0).getRecordNumber());
                        valueList.add(examinationResultsPoVo);
                        //一人的分数即团队得分
                        double totalAverageScore = Double.parseDouble(valueList.get(0).getAverageScore());
                        valueList.get(0).setTotalAverageScore(String.valueOf(Double.valueOf(valueList.get(0).getAverageScore()) + Double.valueOf(valueList.get(0).getJkScore())));
                        valueList.get(1).setTotalAverageScore(String.valueOf(Double.valueOf(valueList.get(1).getAverageScore()) + Double.valueOf(valueList.get(1).getJkScore())));
                    }
                }
                //两名选手
                else if(valueList.size()>1){
                    if (valueList.get(0).getJkScore() == null){
                        valueList.get(0).setJkScore("0.0");
                    }
                    if (valueList.get(1).getJkScore() == null){
                        valueList.get(1).setJkScore("0.0");
                    }
                    //计算团队得分
                    BigDecimal averageScore = new BigDecimal(Double.valueOf(valueList.get(0).getAverageScore()) + Double.valueOf(valueList.get(0).getJkScore()));
                    BigDecimal averageScore2 = new BigDecimal(Double.valueOf(valueList.get(1).getAverageScore()) + Double.valueOf(valueList.get(1).getJkScore()));
                    BigDecimal totalAverageScore = averageScore.add(averageScore2);
                    totalAverageScore = totalAverageScore.setScale(2, RoundingMode.HALF_UP);
                    valueList.get(0).setTotalAverageScore(String.valueOf(totalAverageScore));
                    valueList.get(1).setTotalAverageScore(String.valueOf(totalAverageScore));

                    //判断是否已经解密
                    ExaminationResultsPoVo examinationResultsPoVo = new ExaminationResultsPoVo();
                    examinationResultsPoVo.setDecrypt(0);
                    //两个都未解密
                    if(valueList.get(0).getDecrypt()==0 && valueList.get(1).getDecrypt()==0){
                        valueList = new ArrayList<>();
                        valueList.add(examinationResultsPoVo);
                        valueList.add(examinationResultsPoVo);
                    }
                    //只有一个未解密
                    else if (valueList.get(0).getDecrypt()==0 || valueList.get(1).getDecrypt()==0) {
                        valueList.get(0).setTotalAverageScore("******");
                        valueList.get(1).setTotalAverageScore("******");
                        if(valueList.get(0).getDecrypt()==0){
                            valueList.remove(0);
                            valueList.add(examinationResultsPoVo);
                        } else if (valueList.get(1).getDecrypt()==0) {
                            valueList.remove(1);
                            valueList.add(examinationResultsPoVo);
                        }
                    }
                }
                pageList.addAll(valueList);
            }

            //判断最高分和最低分是否隐藏
            boolean hasDecryptZero = pageList.stream()
                    .anyMatch(examinationResultsPoVo -> {
                        Integer decrypt = examinationResultsPoVo.getDecrypt();
                        return decrypt != null && decrypt == 0; // 先检查decrypt是否为null，再比较是否等于0
                    });
            if(hasDecryptZero){
                pageList.get(0).setMaxScore("******");
                pageList.get(0).setMinScore("******");
            }else{
                //获取最大值最小值
                // 获取最大值
                OptionalDouble maxScore = pageList.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .max();
                double maxValue = maxScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                // 获取最小值
                OptionalDouble minScore = pageList.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .min();
                double minValue = minScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                pageList.get(0).setMaxScore(String.valueOf(maxValue));
                pageList.get(0).setMinScore(String.valueOf(minValue));
            }
            pageList.get(0).setPeopleNumber(pageList.size());
            page.setTotal(pageList.size());
        }
        page.setRecords(pageList);
        return page;
    }

    /**
     * 制定照护计划分数统计导出
     * @return
     */
    @Override
    public void zhiDingDownloadImport(HttpServletResponse response, ExaminationResultsComDO examinationAnswerSheetComDT) {
        Map map =new HashMap();
        map.put("field","A");
        List<ZhiDingScoreExcelVo> pageList = new ArrayList<>();
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);
        if(null!=examinationResultsPoVos && !examinationResultsPoVos.isEmpty()){
            Map<String, List<ExaminationResultsPoVo>> groupedMap = examinationResultsPoVos.stream()
                    .collect(Collectors.groupingBy(ExaminationResultsPoVo::getUnitName));
            for (Map.Entry<String, List<ExaminationResultsPoVo>> entry : groupedMap.entrySet()){
                List<ExaminationResultsPoVo> valueList = entry.getValue();
                ZhiDingScoreExcelVo soreStatisticsVo = new ZhiDingScoreExcelVo();
                List<ZhiDingScoreChildrenExcelVo> childrenExcelList = new ArrayList<>();
                soreStatisticsVo.setUnitName(entry.getKey());//院校名称
//                soreStatisticsVo.setRecordNumber(valueList.get(0).getRecordNumber());//检录号

                //计算裁判平均分
                for (ExaminationResultsPoVo examinationResultsPoVo : valueList) {
                    ZhiDingScoreChildrenExcelVo zhiDingScoreChildrenExcelVo = new ZhiDingScoreChildrenExcelVo();
                    getAvgZhiDing(examinationResultsPoVo);
                    BeanUtils.copyProperties(examinationResultsPoVo,zhiDingScoreChildrenExcelVo);
                    Wrapper<ExaminationResultsComDO> jkWrapper =  new EntityWrapper<ExaminationResultsComDO>();
                    jkWrapper.eq("field","C");
                    jkWrapper.eq("num2",examinationResultsPoVo.getNum2());
                    List<ExaminationResultsComDO> examinationResultsComDOS = examinationResultsComService.selectList(jkWrapper);
                    if (examinationResultsComDOS.size()>0){
                        ExaminationResultsComDO exr =  examinationResultsComDOS.get(0);
                        zhiDingScoreChildrenExcelVo.setJkScore(String.valueOf(exr.getTotalScore())); //机考成绩
                        zhiDingScoreChildrenExcelVo.setScAverageScore(String.valueOf(Double.valueOf(zhiDingScoreChildrenExcelVo.getAverageScore()) + Double.valueOf(zhiDingScoreChildrenExcelVo.getJkScore()))); //赛场得分
                    }

                    childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                }
                //只存在一位选手的时候
                if(valueList.size()==1){
                    ZhiDingScoreChildrenExcelVo zhiDingScoreChildrenExcelVo = new ZhiDingScoreChildrenExcelVo();
                    if(childrenExcelList.get(0).getDecrypt()==0){
                        childrenExcelList = new ArrayList<>();
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                    }else {
                        //一位选手的得分及团队得分
                        ExaminationResultsCopyPoVo examinationResultsCopyPoVo = new ExaminationResultsCopyPoVo();
                        BeanUtils.copyProperties(examinationResultsCopyPoVo,zhiDingScoreChildrenExcelVo);
                        double totalAverageScore = Double.parseDouble(childrenExcelList.get(0).getAverageScore());//总成绩
                        soreStatisticsVo.setTotalAverageScore(String.valueOf(totalAverageScore + Double.valueOf(zhiDingScoreChildrenExcelVo.getJkScore())));
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                    }
                }
                //两位选手
                if(valueList.size()>1){
                    //计算团队得分
                    BigDecimal averageScore = new BigDecimal(Double.valueOf(childrenExcelList.get(0).getAverageScore()) + Double.valueOf(childrenExcelList.get(0).getJkScore()));
                    BigDecimal averageScore2 = new BigDecimal(Double.valueOf(childrenExcelList.get(1).getAverageScore()) + Double.valueOf(childrenExcelList.get(1).getJkScore()));
                    BigDecimal totalAverageScore = averageScore.add(averageScore2);
                    totalAverageScore = totalAverageScore.setScale(2, RoundingMode.HALF_UP);
                    soreStatisticsVo.setTotalAverageScore(String.valueOf(totalAverageScore));
                    //判断是否已经解密
                    ZhiDingScoreChildrenExcelVo zhiDingScoreChildrenExcelVo = new ZhiDingScoreChildrenExcelVo();
                    zhiDingScoreChildrenExcelVo.setDecrypt(0);
                    if(childrenExcelList.get(0).getDecrypt()==0 && childrenExcelList.get(1).getDecrypt()==0){
                        childrenExcelList = new ArrayList<>();
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        soreStatisticsVo = new ZhiDingScoreExcelVo();
                    } else if (childrenExcelList.get(0).getDecrypt()==0 || childrenExcelList.get(1).getDecrypt()==0) {
                        soreStatisticsVo.setTotalAverageScore("******");
                        if(childrenExcelList.get(0).getDecrypt()==0){
                            childrenExcelList.remove(0);
                            childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        } else if (valueList.get(1).getDecrypt()==0) {
                            childrenExcelList.remove(1);
                            childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        }
                    }
                }
                soreStatisticsVo.setScoreList(childrenExcelList);
                pageList.add(soreStatisticsVo);
            }
        }
        //导出操作
        EasyPoiUtil.exportExcel(pageList, "制定照护计划分数导出", "制定照护计划分数导出", ZhiDingScoreExcelVo.class, "制定照护计划分数导出", response);
    }









    public void importYyrby(HttpServletResponse response,String field) {

        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc1(map);

        //获取裁判数。
        int rSum = 0;//裁判数量
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
            //没打分的成绩默认显示 -
            setSc(Double.valueOf(examinationResultsPoVos.get(i).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore5()),examinationResultsPoVos.get(i));
        }
        //导出操作
        EasyPoiUtil.exportExcel(examinationResultsPoVos, "实操婴幼儿保育分数导出", "实操婴幼儿保育分数导出", ScResultVO.class, "实操婴幼儿保育分数导出", response);
    }








    /**
     * 赋默认值
     * @param s1
     * @param s2
     * @param s3
     * @param s4
     * @param s5
     * @return
     */
    private ScResultVO setSc(Double s1,Double s2,Double s3,Double s4,Double s5,ScResultVO scResultVO){
        if (s1 <= 0.0){
            scResultVO.setScore1("-");
        }
        if (s2 <=0.0){
            scResultVO.setScore2("-");
        }
        if (s3 <=0.0){
            scResultVO.setScore3("-");
        }
        if (s4 <=0.0){
            scResultVO.setScore4("-");
        }
        if (s5 <=0.0){
            scResultVO.setScore5("-");
        }
        return scResultVO;
    }









    /**
     * 职业素养测评分数统计
     * @return
     */
    @Override
    public Page<ExaminationResultsPoVo> zhiYeStatistics(ExaminationResultsComDO examinationResultsComDO) {
        Map map =new HashMap();
        map.put("field","C");
        Page<ExaminationResultsPoVo> page = new Page<>(examinationResultsComDO.getPageNumber(), examinationResultsComDO.getPageSize());//分页
        List<ExaminationResultsPoVo> pageList = new ArrayList<>();
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);
        if(null!=examinationResultsPoVos && !examinationResultsPoVos.isEmpty()){
            Map<String, List<ExaminationResultsPoVo>> groupedMap = examinationResultsPoVos.stream()
                    .collect(Collectors.groupingBy(ExaminationResultsPoVo::getUnitName));
            for (Map.Entry<String, List<ExaminationResultsPoVo>> entry : groupedMap.entrySet()){
                List<ExaminationResultsPoVo> valueList = entry.getValue();
                //考虑一名选手的情况
                if(valueList.size()==1){
                    //判断是否已经解密
                    ExaminationResultsPoVo examinationResultsPoVo = new ExaminationResultsPoVo();
                    if(valueList.get(0).getDecrypt()==0){
                        examinationResultsPoVo.setDecrypt(0);
                        valueList = new ArrayList<>();
                        valueList.add(examinationResultsPoVo);
                        valueList.add(examinationResultsPoVo);
                    } else {
                        ExaminationResultsCopyPoVo examinationResultsCopyPoVo = new ExaminationResultsCopyPoVo();
                        BeanUtils.copyProperties(examinationResultsCopyPoVo,examinationResultsPoVo);
                        examinationResultsPoVo.setDecrypt(1);
                        examinationResultsPoVo.setRecordNumber(valueList.get(0).getRecordNumber());
                        valueList.add(examinationResultsPoVo);
                        //一人的分数即团队得分
                        double totalAverageScore = Double.parseDouble(valueList.get(0).getAverageScore());
                        valueList.get(0).setTotalAverageScore(String.valueOf(totalAverageScore));
                        valueList.get(1).setTotalAverageScore(String.valueOf(totalAverageScore));
                    }
                }
                else if(valueList.size()>1){
                    //计算团队得分
                    BigDecimal averageScore = new BigDecimal(valueList.get(0).getAverageScore());
                    BigDecimal averageScore2 = new BigDecimal(valueList.get(1).getAverageScore());
                    BigDecimal totalAverageScore = averageScore.add(averageScore2);
                    valueList.get(0).setTotalAverageScore(String.valueOf(totalAverageScore));
                    valueList.get(1).setTotalAverageScore(String.valueOf(totalAverageScore));

                    //判断是否已经解密
                    ExaminationResultsPoVo examinationResultsPoVo = new ExaminationResultsPoVo();
                    examinationResultsPoVo.setDecrypt(0);
                    //两个都未解密
                    if(valueList.get(0).getDecrypt()==0 && valueList.get(1).getDecrypt()==0){
                        valueList = new ArrayList<>();
                        valueList.add(examinationResultsPoVo);
                        valueList.add(examinationResultsPoVo);
                    }
                    //一个已经解密
                    else if (valueList.get(0).getDecrypt()==0 || valueList.get(1).getDecrypt()==0) {
                        valueList.get(0).setTotalAverageScore("******");
                        valueList.get(1).setTotalAverageScore("******");
                        if(valueList.get(0).getDecrypt()==0){
                            valueList.remove(0);
                            valueList.add(examinationResultsPoVo);
                        } else if (valueList.get(1).getDecrypt()==0) {
                            valueList.remove(1);
                            valueList.add(examinationResultsPoVo);
                        }
                    }
                }
                pageList.addAll(valueList);
            }

            //判断最高分和最低分是否隐藏
            boolean hasDecryptZero = pageList.stream()
                    .anyMatch(examinationResultsPoVo -> {
                        Integer decrypt = examinationResultsPoVo.getDecrypt();
                        return decrypt != null && decrypt == 0; // 先检查decrypt是否为null，再比较是否等于0
                    });
            if(hasDecryptZero){
                pageList.get(0).setMaxScore("******");
                pageList.get(0).setMinScore("******");
            }else{
                //获取最大值最小值
                // 获取最大值
                OptionalDouble maxScore = pageList.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .max();
                double maxValue = maxScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                // 获取最小值
                OptionalDouble minScore = pageList.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .min();
                double minValue = minScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                pageList.get(0).setMaxScore(String.valueOf(maxValue));
                pageList.get(0).setMinScore(String.valueOf(minValue));
            }
            pageList.get(0).setPeopleNumber(pageList.size());
            page.setTotal(pageList.size());
        }
        page.setRecords(pageList);
        return page;
    }

    /**
     * 职业素养测评分数导出
     * @param response
     * @param examinationAnswerSheetComDT
     */
    @Override
    public void zhiYeDownloadImport(HttpServletResponse response, ExaminationResultsComDO examinationAnswerSheetComDT) {
        Map map =new HashMap();
        map.put("field","C");
        List<ZhiYeScoreExcelVo> pageList = new ArrayList<>();
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);
        if(null!=examinationResultsPoVos && !examinationResultsPoVos.isEmpty()){
            Map<String, List<ExaminationResultsPoVo>> groupedMap = examinationResultsPoVos.stream()
                    .collect(Collectors.groupingBy(ExaminationResultsPoVo::getUnitName));
            for (Map.Entry<String, List<ExaminationResultsPoVo>> entry : groupedMap.entrySet()){
                List<ExaminationResultsPoVo> valueList = entry.getValue();
                ZhiYeScoreExcelVo zhiDingScoreExcelVo = new ZhiYeScoreExcelVo();
                List<ZhiYeScoreChildrenExcelVo> childrenExcelList = new ArrayList<>();
                zhiDingScoreExcelVo.setUnitName(entry.getKey());//院校名称
                zhiDingScoreExcelVo.setRecordNumber(valueList.get(0).getRecordNumber());//检录号
                for (ExaminationResultsPoVo examinationResultsPoVo : valueList) {
                    ZhiYeScoreChildrenExcelVo zhiYeScoreChildrenExcelVo = new ZhiYeScoreChildrenExcelVo();
                    BeanUtils.copyProperties(examinationResultsPoVo,zhiYeScoreChildrenExcelVo);
                    childrenExcelList.add(zhiYeScoreChildrenExcelVo);
                }
                //一位选手的情况
                if(valueList.size()==1){
                    ZhiYeScoreChildrenExcelVo zhiYeScoreChildrenExcelVo = new ZhiYeScoreChildrenExcelVo();
                    if(childrenExcelList.get(0).getDecrypt()==0){
                        childrenExcelList = new ArrayList<>();
                        childrenExcelList.add(zhiYeScoreChildrenExcelVo);
                        childrenExcelList.add(zhiYeScoreChildrenExcelVo);
                    }else {
                        //一位选手的得分及团队得分
                        ExaminationResultsCopyPoVo examinationResultsCopyPoVo = new ExaminationResultsCopyPoVo();
                        BeanUtils.copyProperties(examinationResultsCopyPoVo,zhiYeScoreChildrenExcelVo);
                        zhiDingScoreExcelVo.setTotalAverageScore(String.valueOf(valueList.get(0).getAverageScore()));//总成绩
                        childrenExcelList.add(zhiYeScoreChildrenExcelVo);
                    }

                }
                else if(valueList.size()>1){
                    //计算团队得分
                    BigDecimal averageScore = new BigDecimal(valueList.get(0).getAverageScore());
                    BigDecimal averageScore2 = new BigDecimal(valueList.get(1).getAverageScore());
                    BigDecimal totalAverageScore = averageScore.add(averageScore2);
                    zhiDingScoreExcelVo.setTotalAverageScore(String.valueOf(totalAverageScore));
                    //判断是否已经解密
                    ZhiYeScoreChildrenExcelVo zhiDingScoreChildrenExcelVo = new ZhiYeScoreChildrenExcelVo();
                    zhiDingScoreChildrenExcelVo.setDecrypt(0);
                    if(valueList.get(0).getDecrypt()==0 && valueList.get(1).getDecrypt()==0){
                        childrenExcelList = new ArrayList<>();
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        zhiDingScoreExcelVo = new ZhiYeScoreExcelVo();
                    } else if (valueList.get(0).getDecrypt()==0 || valueList.get(1).getDecrypt()==0) {
                        zhiDingScoreExcelVo.setTotalAverageScore("******");
                        if(valueList.get(0).getDecrypt()==0){
                            childrenExcelList.remove(0);
                            childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        } else if (valueList.get(1).getDecrypt()==0) {
                            childrenExcelList.remove(1);
                            childrenExcelList.add(zhiDingScoreChildrenExcelVo);
                        }
                    }
                }
                zhiDingScoreExcelVo.setScoreList(childrenExcelList);
                pageList.add(zhiDingScoreExcelVo);
            }
        }
        //导出操作
        EasyPoiUtil.exportExcel(pageList, "职业素养测评分数导出", "职业素养测评分数导出", ZhiYeScoreExcelVo.class, "职业素养测评分数导出", response);
    }

    /**
     * 实操居家场景分数统计
     * @return
     */
    @Override
    public Page<ExaminationResultsPoVo> juJiaStatistics(ExaminationResultsComDO examinationResultsComDO) {
        Page<ExaminationResultsPoVo> page = new Page<>(examinationResultsComDO.getPageNumber(), examinationResultsComDO.getPageSize());//分页
        Map map =new HashMap();
        map.put("field","B1");
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);
        boolean flag = false;//用来判断是否显示最高分最低分
        if (examinationResultsPoVos!=null && !examinationResultsPoVos.isEmpty()) {
            int i=0;
            for (ExaminationResultsPoVo examinationResultsPoVo : examinationResultsPoVos) {
                if(examinationResultsPoVo.getDecrypt()==0){
                    examinationResultsPoVos.set(i, new ExaminationResultsPoVo()); // 将满足条件的元素设置为null
                    flag = true;
                }else{
                    //计算裁判打分平均分和最终得分
                    getAvgJuJia(examinationResultsPoVo);
                }
                i+=1;
            }
            if(flag){
                examinationResultsPoVos.get(0).setMaxScore("******");
                examinationResultsPoVos.get(0).setMinScore("******");
            }else{
                //获取最高分
                //获取最大值
                OptionalDouble maxScore = examinationResultsPoVos.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .max();
                double maxValue = maxScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                // 获取最小值
                OptionalDouble minScore = examinationResultsPoVos.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .min();
                double minValue = minScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                examinationResultsPoVos.get(0).setMaxScore(String.valueOf(maxValue));
                examinationResultsPoVos.get(0).setMinScore(String.valueOf(minValue));
            }
            examinationResultsPoVos.get(0).setPeopleNumber(examinationResultsPoVos.size());
            page.setRecords(examinationResultsPoVos);
            page.setTotal(examinationResultsPoVos.size());
        }

        return page;
    }

    private static Double safeConvertToDouble(String value) {
        try {
            Double number = Double.parseDouble(value);
            if (number.isNaN()) {
                throw new NumberFormatException("Value is NaN"); // 明确处理NaN情况
            }
            return number;
        } catch (NumberFormatException e) {
            // 如果转换失败或结果是NaN，可以根据需要处理，这里简单地返回0.0作为默认值
            return 0.0;
        }
    }
    @Override
    public Page<ScResultVO> yyrbyStatistics(String field,int number,int sizi) {
        Page<ScResultVO> page = new Page<>(number,sizi);//分页
        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc1(map);

//        //获取裁判数。
        int rSum = 0;//裁判数量
//        if (!examinationResultsPoVos.isEmpty()) {
//            rSum = getRefereesSum(
//                    examinationResultsPoVos.get(0).getScore1(),
//                    examinationResultsPoVos.get(0).getScore2(),
//                    examinationResultsPoVos.get(0).getScore3(),
//                    examinationResultsPoVos.get(0).getScore4(),
//                    examinationResultsPoVos.get(0).getScore5()
//            );
//        }
//
//        for (ScResultVO record : examinationResultsPoVos) {
//            String age = scoreAge1(rSum, record);
//            record.setScoreAge1(age);
//        }
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
        }

        page.setRecords(examinationResultsPoVos);
        page.setTotal(examinationResultsPoVos.size());
        return page;
    }

    public Map yyrbyStatistics(String field) {
        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc1(map);

        //获取裁判数。
        int rSum = 0;//裁判数量
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        } else {
            Map rstMap =new HashMap();
            rstMap.put("max","0");
            rstMap.put("min","0");
            rstMap.put("size","0");
            return rstMap;
        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
        }
        //获取最高分，最低分
        String[] maxAndMin = getMaxAndMin(examinationResultsPoVos);

        Map rstMap =new HashMap();
        rstMap.put("max",maxAndMin[0]);
        rstMap.put("min",maxAndMin[1]);
        rstMap.put("size",examinationResultsPoVos.size());
        return rstMap;
    }























    @Override
    public Page<ScResultVO> zqxxStatistics(String field,int number,int sizi) {
        Page<ScResultVO> page = new Page<>(number,sizi);//分页
        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc2(map);

        //获取裁判数。
        int rSum = 0;//裁判数量
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        }
//        int rSum = 0;//裁判数量
//        if (!examinationResultsPoVos.isEmpty()) {
//            rSum = getRefereesSum(
//                    examinationResultsPoVos.get(0).getScore1(),
//                    examinationResultsPoVos.get(0).getScore2(),
//                    examinationResultsPoVos.get(0).getScore3(),
//                    examinationResultsPoVos.get(0).getScore4(),
//                    examinationResultsPoVos.get(0).getScore5()
//            );
//        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
        }

        page.setRecords(examinationResultsPoVos);
        page.setTotal(examinationResultsPoVos.size());
        return page;
    }

    public Map zqxxStatistics(String field) {
        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc2(map);

        //获取裁判数。
        int rSum = 0;//裁判数量
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        }else {
            Map rstMap =new HashMap();
            rstMap.put("max","0");
            rstMap.put("min","0");
            rstMap.put("size","0");
            return rstMap;
        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
        }
        //获取最高分，最低分
        String[] maxAndMin = getMaxAndMin(examinationResultsPoVos);

        Map rstMap =new HashMap();
        rstMap.put("max",maxAndMin[0]);
        rstMap.put("min",maxAndMin[1]);
        rstMap.put("size",examinationResultsPoVos.size());
        return rstMap;
    }

    public void importZqfz(HttpServletResponse response,String field) {

        Map map =new HashMap();
        map.put("field",field);
        List<ScResultVO> examinationResultsPoVos = this.baseMapper.listScoreSc2(map);

        //获取裁判数。
        int rSum = 0;//裁判数量
        if (examinationResultsPoVos.size()>0){
            rSum = getRefereesSum(Double.valueOf(examinationResultsPoVos.get(0).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(0).getScore5()));
        }
        //根据裁判数量计算平均分
        for (int i=0;i<examinationResultsPoVos.size();i++){
            String age = scoreAge(rSum, examinationResultsPoVos.get(i));
            examinationResultsPoVos.get(i).setScoreAge1(age);
            //没打分的成绩默认显示 -
            setSc(Double.valueOf(examinationResultsPoVos.get(i).getScore1()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore2()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore3()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore4()),
                    Double.valueOf(examinationResultsPoVos.get(i).getScore5()),examinationResultsPoVos.get(i));
        }
        //导出操作
        EasyPoiUtil.exportExcel(examinationResultsPoVos, "实操婴幼儿早期学习支持分数导出", "实操婴幼儿早期学习支持分数导出", ScResultVO.class, "实操婴幼儿早期学习支持分数导出", response);
    }
















    /**
     * 获取最高分最低分
     * @param scoreList
     * @return
     */
    public String[] getMaxAndMin(List<ScResultVO> scoreList) {
        String [] rst = new String[2];
        // 初始化最高分和最低分为第一个考生的分数
        double highestScore = Double.parseDouble(scoreList.get(0).getScoreAge1());
        double lowestScore = Double.parseDouble(scoreList.get(0).getScoreAge1());

        // 遍历集合，找出最高分和最低分
        for (ScResultVO student : scoreList) {
            if (Double.valueOf(student.getScoreAge1()) > highestScore) {
                // 更新最高分
                highestScore = Double.valueOf(student.getScoreAge1());
            }
            if (Double.valueOf(student.getScoreAge1()) < lowestScore) {
                // 更新最低分
                lowestScore = Double.valueOf(student.getScoreAge1());
            }
        }
        rst[0] = String.valueOf(highestScore); //最高分
        rst[1] = String.valueOf(lowestScore); //最低分
        return  rst;
    }


    //平均分计算
//    private String scoreAge1(int reSum, ScResultVO scResultVO) {
//        Double sum = 0.0;
//        switch (reSum) {
//            case 3:
//                sum = safeConvertToDouble(scResultVO.getScore1()) +
//                        safeConvertToDouble(scResultVO.getScore2()) +
//                        safeConvertToDouble(scResultVO.getScore3());
//                break;
//            case 4:
//                sum = safeConvertToDouble(scResultVO.getScore1()) +
//                        safeConvertToDouble(scResultVO.getScore2()) +
//                        safeConvertToDouble(scResultVO.getScore3()) +
//                        safeConvertToDouble(scResultVO.getScore4());
//                break;
//            case 5:
//                sum = safeConvertToDouble(scResultVO.getScore1()) +
//                        safeConvertToDouble(scResultVO.getScore2()) +
//                        safeConvertToDouble(scResultVO.getScore3()) +
//                        safeConvertToDouble(scResultVO.getScore4()) +
//                        safeConvertToDouble(scResultVO.getScore5());
//                break;
//        }
//        return String.format("%.2f", sum / reSum); // 保留两位小数
//    }

    //平均分计算
    private String scoreAge(int reSum,ScResultVO scResultVO){
        Double sum = 0.0; //总分

        if (reSum == 3){
          sum = Double.valueOf(scResultVO.getScore1()) + Double.valueOf(scResultVO.getScore2()) +Double.valueOf(scResultVO.getScore3());
        }else if (reSum == 4){
            sum = Double.valueOf(scResultVO.getScore1()) + Double.valueOf(scResultVO.getScore2()) +Double.valueOf(scResultVO.getScore3()) +Double.valueOf(scResultVO.getScore4());
        }else if (reSum == 5){
            sum = Double.valueOf(scResultVO.getScore1()) + Double.valueOf(scResultVO.getScore2()) +Double.valueOf(scResultVO.getScore3()) +Double.valueOf(scResultVO.getScore4()) +Double.valueOf(scResultVO.getScore5());
        }
       sum = sum / reSum;
        String formattedAge = new DecimalFormat("#.##").format(sum);
        return formattedAge;
    }



    /**
     * 获取裁判数量
     * @return
     */
//    private int getRefereesSum(String s1, String s2, String s3, String s4, String s5) {
//        int referees = 0;
//        if (safeConvertToDouble(s1) >= 0.0) referees++;
//        if (safeConvertToDouble(s2) >= 0.0) referees++;
//        if (safeConvertToDouble(s3) >= 0.0) referees++;
//        if (safeConvertToDouble(s4) >= 0.0) referees++;
//        if (safeConvertToDouble(s5) >= 0.0) referees++;
//        return referees;
//    }
    /**
     * 获取裁判数量
     * @return
     */
    private int getRefereesSum(Double s1,Double s2,Double s3,Double s4,Double s5){
        int referees = 0; //默认没有裁判
        if (s1 >= 0.0){
            referees++;
        }
        if (s2 >=0.0){
            referees++;
        }
        if (s3 >=0.0){
            referees++;
        }
        if (s4 >=0.0){
            referees++;
        }
        if (s5 >=0.0){
            referees++;
        }
        return referees;
    }
















    /**
     * 实操居家场景分数统计导出
     * @param response
     * @param examinationAnswerSheetComDT
     */
    @Override
    public void juJiaDownloadImport(HttpServletResponse response, ExaminationResultsComDO examinationAnswerSheetComDT) {
        examinationAnswerSheetComDT.setPageNumber(1);
        examinationAnswerSheetComDT.setPageSize(9999);
        List<ExaminationResultsPoVo> records = this.juJiaStatistics(examinationAnswerSheetComDT).getRecords();
        List<JuJiaScoreExcelVo> juJiaScoreExcelVoList = new ArrayList<>();
        if (records!=null && !records.isEmpty()) {
            for (ExaminationResultsPoVo record : records) {
                JuJiaScoreExcelVo juJiaScoreExcelVo = new JuJiaScoreExcelVo();
                BeanUtils.copyProperties(record,juJiaScoreExcelVo);
                juJiaScoreExcelVoList.add(juJiaScoreExcelVo);
            }
        }
        //导出操作
        EasyPoiUtil.exportExcel(juJiaScoreExcelVoList, "实操居家场景分数统计导出", "实操居家场景分数统计导出", JuJiaScoreExcelVo.class, "实操居家场景分数统计导出", response);
    }

    /**
     * 月子中心场景成绩统计
     * @param examinationResultsComDO
     * @return
     */
    @Override
    public Page<ExaminationResultsPoVo> yueZiStatistics(ExaminationResultsComDO examinationResultsComDO) {
        Page<ExaminationResultsPoVo> page = new Page<>(examinationResultsComDO.getPageNumber(), examinationResultsComDO.getPageSize());//分页
        Map map =new HashMap();
        map.put("field","B2");
        List<ExaminationResultsPoVo> examinationResultsPoVos = this.baseMapper.listScore(map);
        boolean flag = false;//用来判断是否显示最高分最低分
        if (examinationResultsPoVos!=null && !examinationResultsPoVos.isEmpty()) {
            int i=0;
            for (ExaminationResultsPoVo examinationResultsPoVo : examinationResultsPoVos) {
                if(examinationResultsPoVo.getDecrypt()==0){
                    examinationResultsPoVos.set(i, new ExaminationResultsPoVo()); // 将满足条件的元素设置为null
                    flag = true;
                }else{
                    //计算裁判打分平均分和最终得分
                    getAvgJuJia(examinationResultsPoVo);
                }
                i+=1;
            }
            if(flag){
                examinationResultsPoVos.get(0).setMaxScore("******");
                examinationResultsPoVos.get(0).setMinScore("******");
            }else{
                //获取最高分
                //获取最大值
                OptionalDouble maxScore = examinationResultsPoVos.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .max();
                double maxValue = maxScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                // 获取最小值
                OptionalDouble minScore = examinationResultsPoVos.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .min();
                double minValue = minScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                examinationResultsPoVos.get(0).setMaxScore(String.valueOf(maxValue));
                examinationResultsPoVos.get(0).setMinScore(String.valueOf(minValue));
            }
            examinationResultsPoVos.get(0).setPeopleNumber(examinationResultsPoVos.size());
            page.setRecords(examinationResultsPoVos);
            page.setTotal(examinationResultsPoVos.size());
        }

        return page;
    }

    /**
     * 月子中心场景分数统计导出
     * @param response
     * @param examinationAnswerSheetComDT
     */
    @Override
    public void yueZiDownloadImport(HttpServletResponse response, ExaminationResultsComDO examinationAnswerSheetComDT) {
        examinationAnswerSheetComDT.setPageNumber(1);
        examinationAnswerSheetComDT.setPageSize(9999);
        List<ExaminationResultsPoVo> records = this.yueZiStatistics(examinationAnswerSheetComDT).getRecords();
        List<JuJiaScoreExcelVo> juJiaScoreExcelVoList = new ArrayList<>();
        if (records!=null && !records.isEmpty()) {
            for (ExaminationResultsPoVo record : records) {
                JuJiaScoreExcelVo juJiaScoreExcelVo = new JuJiaScoreExcelVo();
                BeanUtils.copyProperties(record,juJiaScoreExcelVo);
                juJiaScoreExcelVoList.add(juJiaScoreExcelVo);
            }
        }
        //导出操作
        EasyPoiUtil.exportExcel(juJiaScoreExcelVoList, "月子中心场景分数统计导出", "月子中心场景分数统计导出", JuJiaScoreExcelVo.class, "月子中心场景分数统计导出", response);
    }

    /**
     * 成绩总统计
     * @param examinationResultsComDO
     * @return
     */
    @Override
    public Page<OverallStatisticsVo> overallStatistics(ExaminationResultsComDO examinationResultsComDO) {
        //判断是都已经全部解密
        boolean flag = false;
        Map<String,OverallStatisticsVo> map = new HashMap<>();
        //查询学校信息
        List<CareStuSignUpComRealityDO> unitNameList = careStuSignUpComRealityService.selectList(new EntityWrapper<CareStuSignUpComRealityDO>().groupBy("unit_name"));
        for (CareStuSignUpComRealityDO careStuSignUpComRealityDO : unitNameList) {
            if(careStuSignUpComRealityDO.getDecryptAll()==0){
                flag = true;
            }
            OverallStatisticsVo overallStatisticsVo = new OverallStatisticsVo();
            BeanUtils.copyProperties(careStuSignUpComRealityDO,overallStatisticsVo);
            map.put(careStuSignUpComRealityDO.getUnitName(),overallStatisticsVo);
        }
        //查询A赛场制定照护计划成绩
        Map mapA =new HashMap();
        mapA.put("field","A");
        List<ExaminationResultsPoVo> listA = this.baseMapper.listScore(mapA);

        //查询C赛场职业素养测评成绩
        Map mapC =new HashMap();
        mapC.put("field","C");
        List<ExaminationResultsPoVo> listC = this.baseMapper.listScore(mapC);

        //查询B赛场居家场景成绩
        Map mapB1 =new HashMap();
        mapB1.put("field","B1");
        List<ExaminationResultsPoVo> listB1 = this.baseMapper.listScore(mapB1);

        //查询B赛场月子场景成绩
        Map mapB2 =new HashMap();
        mapB2.put("field","B2");
        List<ExaminationResultsPoVo> listB2 = this.baseMapper.listScore(mapB2);

        //制定照护计划
        if(listA!=null && !listA.isEmpty()){
            for (ExaminationResultsPoVo examinationResultsPoVo : listA) {
                String name = examinationResultsPoVo.getName();
                String num1 = examinationResultsPoVo.getNum1();
                String num2 = examinationResultsPoVo.getNum2();
                String unitName = examinationResultsPoVo.getUnitName();
                /** 判断是否解密 并且计算裁判打分平均分 */
                getAvgZhiDing(examinationResultsPoVo);

                OverallStatisticsVo overallStatisticsVo = map.get(unitName);
                //选手一
                if(null==overallStatisticsVo.getNameA1() || overallStatisticsVo.getNameA1().equals("-")){
                    BeanUtils.copyProperties(examinationResultsPoVo,overallStatisticsVo);
                    overallStatisticsVo.setNameA1(name);//参赛选手
                    overallStatisticsVo.setNum1A1(num1);//一次加密
                    overallStatisticsVo.setNum2A1(num2);//二次加密
                    overallStatisticsVo.setScoreA1(examinationResultsPoVo.getJudgment());//裁判每项打分
                    overallStatisticsVo.setAvg1(Double.parseDouble(examinationResultsPoVo.getAverageScore()));//裁判打分平均分
                    map.replace(unitName,overallStatisticsVo);
                }
                else{
                    //选手二
                    overallStatisticsVo.setNameA2(name);//参赛选手
                    overallStatisticsVo.setNum1A2(num1);//一次加密
                    overallStatisticsVo.setNum2A2(num2);//二次加密
                    overallStatisticsVo.setScoreA2(examinationResultsPoVo.getJudgment());//裁判每项打分
                    overallStatisticsVo.setAvg2(Double.parseDouble(examinationResultsPoVo.getAverageScore()));//裁判打分平均分
                    overallStatisticsVo.setTotalScoreA(String.valueOf(overallStatisticsVo.getAvg1() + overallStatisticsVo.getAvg2()));//制定照护计划最终得分
                    map.replace(examinationResultsPoVo.getUnitName(),overallStatisticsVo);
                }
            }
        }
        //居家场景
        if(listB1!=null && !listB1.isEmpty()){
            for (ExaminationResultsPoVo examinationResultsPoVo : listB1) {
                String num1 = examinationResultsPoVo.getNum1();
                String num2 = examinationResultsPoVo.getNum2();
                String unitName = examinationResultsPoVo.getUnitName();

                /** 判断是否解密 并且计算裁判打分平均分 */
                getAvgJuJia(examinationResultsPoVo);

                OverallStatisticsVo overallStatisticsVo = new OverallStatisticsVo();
                if(map.containsKey(unitName)){
                    overallStatisticsVo = map.get(unitName);
                }
                overallStatisticsVo.setRecordNumber(examinationResultsPoVo.getRecordNumber());
                overallStatisticsVo.setUnitName(unitName);
                overallStatisticsVo.setDecrypt(examinationResultsPoVo.getDecrypt());
                overallStatisticsVo.setNum1B1(num1);//一次加密
                overallStatisticsVo.setNum2B1(num2);//二次加密
                overallStatisticsVo.setScoreB1One(examinationResultsPoVo.getJudgment());//居家场景婴幼儿照护打分
                overallStatisticsVo.setScoreB1Two(examinationResultsPoVo.getJudgment2());//居家场景产妇照护打分打分
                overallStatisticsVo.setTotalScoreB1(examinationResultsPoVo.getTotalAverageScore());//裁判打分平均分

                if(map.containsKey(unitName)){
                    map.replace(unitName,overallStatisticsVo);
                }else {
                    map.put(unitName,overallStatisticsVo);
                }
            }
        }
        //月子场景
        if(listB2!=null && !listB2.isEmpty()){
            for (ExaminationResultsPoVo examinationResultsPoVo : listB2) {
                String num1 = examinationResultsPoVo.getNum1();
                String num2 = examinationResultsPoVo.getNum2();
                String unitName = examinationResultsPoVo.getUnitName();

                /** 判断是否解密 并且计算裁判打分平均分 */
                getAvgJuJia(examinationResultsPoVo);

                OverallStatisticsVo overallStatisticsVo = new OverallStatisticsVo();
                if(map.containsKey(unitName)){
                    overallStatisticsVo = map.get(unitName);
                }
                overallStatisticsVo.setRecordNumber(examinationResultsPoVo.getRecordNumber());
                overallStatisticsVo.setUnitName(unitName);
                overallStatisticsVo.setDecrypt(examinationResultsPoVo.getDecrypt());
                overallStatisticsVo.setNum1B2(num1);//一次加密
                overallStatisticsVo.setNum2B2(num2);//二次加密
                overallStatisticsVo.setScoreB2One(examinationResultsPoVo.getJudgment());//居家场景婴幼儿照护打分
                overallStatisticsVo.setScoreB2Two(examinationResultsPoVo.getJudgment2());//居家场景产妇照护打分打分
                overallStatisticsVo.setTotalScoreB2(examinationResultsPoVo.getTotalAverageScore());//裁判打分平均分
                map.replace(unitName,overallStatisticsVo);
                if(map.containsKey(unitName)){
                    map.replace(unitName,overallStatisticsVo);
                }else{
                    map.put(unitName,overallStatisticsVo);
                }

            }
        }
        //职业素养测评
        if(listC!=null && !listC.isEmpty()){
            Map<String, List<ExaminationResultsPoVo>> groupedMap = listC.stream()
                    .collect(Collectors.groupingBy(ExaminationResultsPoVo::getUnitName));
            for (Map.Entry<String, List<ExaminationResultsPoVo>> entry : groupedMap.entrySet()){

                String unitName = entry.getKey();

                OverallStatisticsVo overallStatisticsVo = new OverallStatisticsVo();
                if(map.containsKey(unitName)){
                    overallStatisticsVo = map.get(unitName);
                }
                List<ExaminationResultsPoVo> valueList = entry.getValue();

                //计算团队得分
                if(valueList.size()==2){
                    overallStatisticsVo.setNameC1(valueList.get(0).getName());//选手姓名
                    overallStatisticsVo.setNum1C1(valueList.get(0).getNum1());//一次加密
                    overallStatisticsVo.setNum2C1(valueList.get(0).getNum2());//二次加密
                    overallStatisticsVo.setScoreC1(valueList.get(0).getAverageScore());//素养测评考试得分
                    overallStatisticsVo.setTotalScoreC(valueList.get(0).getAverageScore());//C赛场总得分

                    overallStatisticsVo.setNameC2(valueList.get(1).getName());
                    overallStatisticsVo.setNum1C2(valueList.get(1).getNum1());
                    overallStatisticsVo.setNum2C2(valueList.get(1).getNum2());
                    overallStatisticsVo.setScoreC2(valueList.get(1).getAverageScore());
                    BigDecimal scoreC1 = new BigDecimal(overallStatisticsVo.getScoreC1());
                    BigDecimal scoreC2 = new BigDecimal(overallStatisticsVo.getScoreC2());
                    overallStatisticsVo.setTotalScoreC(String.valueOf(scoreC1.add(scoreC2)));
                }
                if(map.containsKey(unitName)){
                    map.replace(unitName,overallStatisticsVo);
                }else{
                    map.put(unitName,overallStatisticsVo);
                }
            }
        }
        Page<OverallStatisticsVo> page = new Page<>(examinationResultsComDO.getPageNumber(), examinationResultsComDO.getPageSize());//分页

        List<OverallStatisticsVo> list = new ArrayList<>();
        if(!map.isEmpty()){
            for (Map.Entry<String, OverallStatisticsVo> entry : map.entrySet()){
                OverallStatisticsVo value = entry.getValue();
                BigDecimal totalScoreA = new BigDecimal(0);
                BigDecimal totalScoreB1 = new BigDecimal(0);
                BigDecimal totalScoreB2 = new BigDecimal(0);
                BigDecimal totalScoreC = new BigDecimal(0);
                BigDecimal totalAverageScore = new BigDecimal(0);
                //计算总分
                if(!value.getTotalScoreA().equals("-")){
                    totalScoreA = new BigDecimal(value.getTotalScoreA());
                }
                if(!value.getTotalScoreB1().equals("-")){
                    totalScoreB1 = new BigDecimal(value.getTotalScoreB1());
                }
                if(!value.getTotalScoreB2().equals("-")){
                    totalScoreB2 = new BigDecimal(value.getTotalScoreB2());
                }
                if(!value.getTotalScoreC().equals("-")){
                    totalScoreC = new BigDecimal(value.getTotalScoreC());
                }
                totalAverageScore = totalScoreA.add(totalScoreB1).add(totalScoreB2).add(totalScoreC);;
                value.setTotalAverageScore(String.valueOf(totalAverageScore));
                list.add(value);
            }

            if(flag){
                int size = list.size();
                for (int i = 0; i < size; i++) {
                    OverallStatisticsVo overallStatisticsVo = new OverallStatisticsVo();
                    OverallStatisticsCopyVo overallStatisticsCopyVo = new OverallStatisticsCopyVo();
                    BeanUtils.copyProperties(overallStatisticsCopyVo,overallStatisticsVo);
                    list.set(i,overallStatisticsVo);
                }
            }else {
                //获取最高分
                //获取最大值
                OptionalDouble maxScore = list.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .max();
                double maxValue = maxScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                // 获取最小值
                OptionalDouble minScore = list.stream()
                        .mapToDouble(examinationResultsPoVo -> {
                            // 假设getTotalAverageScore()返回的是String类型的分数
                            String scoreString = examinationResultsPoVo.getTotalAverageScore();
                            // 将String类型的分数转换为double类型
                            return Double.parseDouble(scoreString);
                        })
                        .min();
                double minValue = minScore.orElse(Double.NaN); // 如果列表为空，则返回NaN
                list.get(0).setMaxScore(String.valueOf(maxValue));
                list.get(0).setMinScore(String.valueOf(minValue));
                list.get(0).setPeopleNumber(list.size() * 2);
                page.setTotal(list.size());
            }
        }

        page.setRecords(list);
        return page;
    }









    /**
     * 成绩总统计
     * @return
     */
    @Override
    public Page<ExaminationResultsVO> overallStatistics(int pageNumber,int pageSize) {

        Page<ExaminationResultsVO> page = new Page<>(pageNumber, pageSize);//分页

        Page<CareStuSignUpComRealityDO> page2 = new Page<>(pageNumber, pageSize);//分页

        //查询学校信息
        Page<CareStuSignUpComRealityDO> unitNamePage = careStuSignUpComRealityService.selectPage(page2,new EntityWrapper<CareStuSignUpComRealityDO>().groupBy("unit_name"));
        List<CareStuSignUpComRealityDO> unitNameList = unitNamePage.getRecords();

        if(unitNameList.size()>0){
            if (unitNameList.get(0).getDecryptAll() !=null){
                if (unitNameList.get(0).getDecryptAll() == 0){

                }
            }
        }

        //定义最终返回结果
        List<ExaminationResultsVO> examinationResultsVOs =new ArrayList<>();

        Double sum = 0.0;

        for (int i=0;i<unitNameList.size();i++){

            ExaminationResultsVO examinationResultsVO =new ExaminationResultsVO();
            examinationResultsVO.setUnitName(unitNameList.get(i).getUnitName()); //参赛单位
            examinationResultsVO.setTeamLeader(unitNameList.get(i).getTeamLeader()); //领队
            examinationResultsVO.setTeacher(unitNameList.get(i).getTeacher()); //指导老师

            Wrapper<CareStuSignUpComRealityDO> wrapper = new EntityWrapper<>();
            wrapper.eq("unit_name",unitNameList.get(i).getUnitName());
            List<CareStuSignUpComRealityDO> careStuSignUpComRealityDOS = careStuSignUpComRealityService.selectList(wrapper);//根据学校查询考生信息

            List<StudentResultsVO> studentVOS =new ArrayList<>();
            //遍历该学校下的所有考生
            for (int j=0;j<careStuSignUpComRealityDOS.size();j++){
                StudentResultsVO studentResultsVO =new StudentResultsVO();
                studentResultsVO.setName(careStuSignUpComRealityDOS.get(j).getName()); //选手姓名
                studentResultsVO.setLlCqNumber(careStuSignUpComRealityDOS.get(j).getLlCqNumber()); //理论检录序号
                studentResultsVO.setScCqTrack(careStuSignUpComRealityDOS.get(j).getScCqTrack()); //赛道
                studentResultsVO.setScCqSession(careStuSignUpComRealityDOS.get(j).getScCqSession()); //场次
                studentResultsVO.setScCqNumber(careStuSignUpComRealityDOS.get(j).getScCqNumber()); //实操检录序号




                //理论案例分析题打分总统计
                Map map =new HashMap();
                map.put("field","A");
                map.put("id",careStuSignUpComRealityDOS.get(j).getId()); //账号id
                List<ExaminationResultsPoVo> exaresultsPoVo = this.baseMapper.listScore(map);
                int refereesSum = 0;//裁判数量默认0
                if (exaresultsPoVo.size()>0){
                    ExaminationResultsPoVo examinationResultsPoVo = exaresultsPoVo.get(0);
                    studentResultsVO.setLlnum1(examinationResultsPoVo.getNum1()); //理论一次加密
                    studentResultsVO.setLlnum2(examinationResultsPoVo.getNum2()); //理论二次加密

                    String s = examinationResultsPoVo.getScore1() + "/" + examinationResultsPoVo.getScore2() + "/" + examinationResultsPoVo.getScore3();
                    if (!examinationResultsPoVo.getScore4().equals("-1.00")){
                        s  = s + "/" + examinationResultsPoVo.getScore4();
                    }
                    if (!examinationResultsPoVo.getScore5().equals("-1.00")){
                        s  = s + "/" +examinationResultsPoVo.getScore5(); //案例分析题分数
                    }
                    studentResultsVO.setAlfxtScore(s);
                    //获取裁判数量
                    refereesSum= getRefereesSum(Double.valueOf(examinationResultsPoVo.getScore1()), Double.valueOf(examinationResultsPoVo.getScore2()), Double.valueOf(examinationResultsPoVo.getScore3()), Double.valueOf(examinationResultsPoVo.getScore4()), Double.valueOf(examinationResultsPoVo.getScore5()));
                    double averageScore = (Double.valueOf(examinationResultsPoVo.getScore1()) +
                            Double.valueOf(examinationResultsPoVo.getScore2()) +
                            Double.valueOf(examinationResultsPoVo.getScore3()) +
                            Double.valueOf(examinationResultsPoVo.getScore4()) +
                            Double.valueOf(examinationResultsPoVo.getScore5())) / refereesSum;
                    String formattedAverageScore = String.format("%.2f", averageScore);
                   studentResultsVO.setAScore(formattedAverageScore); //A赛场最终得分
                }

                //理论机考总统计
                Wrapper<ExaminationResultsComDO> jkWrapper =  new EntityWrapper<ExaminationResultsComDO>();
                jkWrapper.eq("field","C");
                jkWrapper.eq("num2",studentResultsVO.getLlnum2());
                List<ExaminationResultsComDO> examinationResultsComDOS = examinationResultsComService.selectList(jkWrapper);
                if (examinationResultsComDOS.size()>0){
                    ExaminationResultsComDO examinationResultsComDO =   examinationResultsComDOS.get(0);
                    studentResultsVO.setJkScore(String.valueOf(examinationResultsComDO.getTotalScore())); //机考成绩
                }

                if (studentResultsVO.getJkScore() != null){
                    if (studentResultsVO.getAScore() !=null) {
                        studentResultsVO.setAScore(String.valueOf(Double.valueOf(studentResultsVO.getAScore()) + Double.valueOf(studentResultsVO.getJkScore())));
                    }
                }




                //实操婴幼儿保育总统计
                map =new HashMap();
                map.put("field",studentResultsVO.getScCqSession());
                map.put("id",careStuSignUpComRealityDOS.get(j).getId());
                List<ScResultVO> scResultVOs = this.baseMapper.listScoreSc1(map);
                if (scResultVOs.size()>0) {
                    ScResultVO scResultVO = scResultVOs.get(0);
                    studentResultsVO.setScnum1(scResultVO.getNum1()); //实操一次加密
                    studentResultsVO.setScnum2(scResultVO.getNum2()); //实操二次加密
                    String s = scResultVO.getScore1() + "/" + scResultVO.getScore2() + "/" + scResultVO.getScore3();
                    if (!scResultVO.getScore4().equals("-1.00")){
                       s = s + "/" + scResultVO.getScore4();
                    }
                    if (!scResultVO.getScore5().equals("-1.00")){
                        s = s + "/" + scResultVO.getScore5();
                    }
                    studentResultsVO.setYyrbyScore(s); //实操婴幼儿保育分数
                    if (refereesSum == 0){
                        refereesSum= getRefereesSum(Double.valueOf(scResultVO.getScore1()), Double.valueOf(scResultVO.getScore2()), Double.valueOf(scResultVO.getScore3()), Double.valueOf(scResultVO.getScore4()), Double.valueOf(scResultVO.getScore5()));
                    }
                    studentResultsVO.setYyrbyScoreZz(new DecimalFormat("#.##").
                            format((Double.valueOf(scResultVO.getScore1()) + Double.valueOf(scResultVO.getScore2())
                                    + Double.valueOf(scResultVO.getScore3()) + Double.valueOf(scResultVO.getScore4())
                                    + Double.valueOf(scResultVO.getScore5())) / refereesSum));
               }else {
                    studentResultsVO.setScnum1("-");
                    studentResultsVO.setScnum2("-");
                    studentResultsVO.setYyrbyScore("-");
                    studentResultsVO.setYyrbyScoreZz("-");
                }

                //实操早期学习总统计
                map =new HashMap();
                map.put("field",studentResultsVO.getScCqSession());
                map.put("id",careStuSignUpComRealityDOS.get(j).getId());
                scResultVOs = this.baseMapper.listScoreSc2(map);
                if (scResultVOs.size()>0) {
                    ScResultVO scResultVO = scResultVOs.get(0);
                    String sb = scResultVO.getScore1() + "/" + scResultVO.getScore2() + "/" + scResultVO.getScore3();
                    if (!scResultVO.getScore4().equals("-1.00")){
                        sb = sb + "/" + scResultVO.getScore4();
                    }
                    if (!scResultVO.getScore5().equals("-1.00")){
                        sb = sb + "/" + scResultVO.getScore5();
                    }
                    studentResultsVO.setZqfzScore(sb); //早期发展学习分数
                    Double s = (Double.valueOf(scResultVO.getScore1()) + Double.valueOf(scResultVO.getScore2()) + Double.valueOf(scResultVO.getScore3()) + Double.valueOf(scResultVO.getScore4()) + Double.valueOf(scResultVO.getScore5())) / refereesSum;
                    String zqfzScoreZz = String.format("%.2f", s);
                    studentResultsVO.setZqfzScoreZz(zqfzScoreZz);
                }else {
                    studentResultsVO.setZqfzScore("-");
                    studentResultsVO.setZqfzScoreZz("-");
                }

                if (studentResultsVO.getJkScore() == null){
                    studentResultsVO.setJkScore("-");
                }
                if (studentResultsVO.getAScore() == null){
                    studentResultsVO.setAScore("-");
                }
                if (studentResultsVO.getYyrbyScoreZz() == null){
                    studentResultsVO.setYyrbyScoreZz("-");
                }
                if (studentResultsVO.getZqfzScoreZz() == null){
                    studentResultsVO.setZqfzScoreZz("-");
                }
                //计算一个人的总成绩
                sum = sum +  (
                        Double.valueOf(studentResultsVO.getJkScore().equals("-")?"0.0":studentResultsVO.getJkScore()) +
                                Double.valueOf(studentResultsVO.getAScore().equals("-")?"0.0":studentResultsVO.getAScore()) +
                                Double.valueOf(studentResultsVO.getYyrbyScoreZz().equals("-")?"0.0":studentResultsVO.getYyrbyScoreZz()) +
                                Double.valueOf(studentResultsVO.getZqfzScoreZz().equals("-")?"0.0":studentResultsVO.getZqfzScoreZz())
                );

                studentVOS.add(studentResultsVO);
            }
            String zzSum = String.format("%.2f", sum);
            examinationResultsVO.setTeamScore(zzSum);
            sum = 0.0;

            examinationResultsVO.setStudentVOs(studentVOS);
            examinationResultsVOs.add(examinationResultsVO);
        }

        page.setTotal(unitNamePage.getTotal());
        page.setRecords(examinationResultsVOs);
        return page;
    }









    /**
     * 获取制定照护计划裁判打分平均分
     * @param examinationResultsPoVo
     */
    public void getAvgZhiDing(ExaminationResultsPoVo examinationResultsPoVo){
        double all = 0.0;
        double avg = 0.0;
        String judgment = "-";//裁判打分 例：50/50/50
        //五位裁判
        if(Double.valueOf(examinationResultsPoVo.getScore5())!=-1){
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3()) + Double.valueOf(examinationResultsPoVo.getScore4())
                    + Double.valueOf(examinationResultsPoVo.getScore5());
            avg = Math.round((all / 5) * 100.0) / 100.0;
            judgment = examinationResultsPoVo.getScore1() +"/"+ examinationResultsPoVo.getScore2() +"/"+ examinationResultsPoVo.getScore3() +"/"+ examinationResultsPoVo.getScore4() +"/"+ examinationResultsPoVo.getScore5();
        }
        //四位裁判
        else if (Double.valueOf(examinationResultsPoVo.getScore4())!=-1){
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3()) + Double.valueOf(examinationResultsPoVo.getScore4());
            avg = Math.round((all / 4) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5("-");
            judgment = examinationResultsPoVo.getScore1() +"/"+ examinationResultsPoVo.getScore2() +"/"+ examinationResultsPoVo.getScore3() +"/"+ examinationResultsPoVo.getScore4();
        }
        //三位
        else {
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3());
            avg = Math.round((all / 3) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5("-");
            examinationResultsPoVo.setScore4("-");
            judgment = examinationResultsPoVo.getScore1() +"/"+ examinationResultsPoVo.getScore2() +"/"+ examinationResultsPoVo.getScore3();
        }
        examinationResultsPoVo.setAverageScore(String.valueOf(avg));
        examinationResultsPoVo.setJudgment(judgment);
    }

    /**
     * 获取居家场景裁判打分平均分
     * @param examinationResultsPoVo
     */
    public void getAvgJuJia(ExaminationResultsPoVo examinationResultsPoVo){
        double all = 0.0;//婴幼儿照护总分
        double avg = 0.0;//婴幼儿照护平均分
        String judgment = "";//裁判打分
        //计算最终得分
        //五位裁判
        if(Double.valueOf(examinationResultsPoVo.getScore5())!=-1){
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3()) + Double.valueOf(examinationResultsPoVo.getScore4())
                    + Double.valueOf(examinationResultsPoVo.getScore5());
            avg = Math.round((all / 5) * 100.0) / 100.0;
            judgment = examinationResultsPoVo.getScore1() + "/" + examinationResultsPoVo.getScore2() + "/" + examinationResultsPoVo.getScore3() + "/" + examinationResultsPoVo.getScore4() + "/" + examinationResultsPoVo.getScore5();
        }
        //四位裁判
        else if (Double.valueOf(examinationResultsPoVo.getScore4())!=-1){
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3()) + Double.valueOf(examinationResultsPoVo.getScore4());
            avg = Math.round((all / 4) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5("-");
            judgment = examinationResultsPoVo.getScore1() + "/" + examinationResultsPoVo.getScore2() + "/" + examinationResultsPoVo.getScore3() + "/" + examinationResultsPoVo.getScore4();
        }
        //三位
        else {
            all = Double.parseDouble(examinationResultsPoVo.getScore1()) + Double.parseDouble(examinationResultsPoVo.getScore2())
                    + Double.parseDouble(examinationResultsPoVo.getScore3());
            avg = Math.round((all / 3) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5("-");
            examinationResultsPoVo.setScore4("-");
            judgment = examinationResultsPoVo.getScore1() + "/" + examinationResultsPoVo.getScore2() + "/" + examinationResultsPoVo.getScore3();
        }

        double allS = 0.0;//产妇照护总分
        double avgS = 0.0;//产妇照护总分
        String judgment1 = "";//裁判打分
        //五位裁判
        if(Double.valueOf(examinationResultsPoVo.getScore5s())!=-1){
            allS = Double.parseDouble(examinationResultsPoVo.getScore1s()) + Double.parseDouble(examinationResultsPoVo.getScore2s())
                    + Double.parseDouble(examinationResultsPoVo.getScore3s()) + Double.valueOf(examinationResultsPoVo.getScore4s())
                    + Double.valueOf(examinationResultsPoVo.getScore5s());
            avgS = Math.round((allS / 5) * 100.0) / 100.0;
            judgment1 = examinationResultsPoVo.getScore1s() + "/" + examinationResultsPoVo.getScore2s() + "/" + examinationResultsPoVo.getScore3s() + "/" + examinationResultsPoVo.getScore4s() + "/" + examinationResultsPoVo.getScore5s();
        }
        //四位裁判
        else if (Double.valueOf(examinationResultsPoVo.getScore4s())!=-1){
            allS = Double.parseDouble(examinationResultsPoVo.getScore1s()) + Double.parseDouble(examinationResultsPoVo.getScore2s())
                    + Double.parseDouble(examinationResultsPoVo.getScore3s()) + Double.valueOf(examinationResultsPoVo.getScore4s());
            avgS = Math.round((allS / 4) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5s("-");
            judgment1 = examinationResultsPoVo.getScore1s() + "/" + examinationResultsPoVo.getScore2s() + "/" + examinationResultsPoVo.getScore3s() + "/" + examinationResultsPoVo.getScore4s();
        }
        //三位
        else {
            allS = Double.parseDouble(examinationResultsPoVo.getScore1s()) + Double.parseDouble(examinationResultsPoVo.getScore2s())
                    + Double.parseDouble(examinationResultsPoVo.getScore3s());
            avgS = Math.round((allS / 3) * 100.0) / 100.0;
            examinationResultsPoVo.setScore5s("-");
            examinationResultsPoVo.setScore4s("-");
            judgment1 = examinationResultsPoVo.getScore1s() + "/" + examinationResultsPoVo.getScore2s() + "/" + examinationResultsPoVo.getScore3s();
        }
        BigDecimal avgDecimal = new BigDecimal(avg);
        BigDecimal avgSDecimal = new BigDecimal(avgS);
        examinationResultsPoVo.setTotalAverageScore(String.valueOf(avgDecimal.add(avgSDecimal).setScale(2, RoundingMode.HALF_UP)));//选手最终得分
        examinationResultsPoVo.setAverageScore1(avg);
        examinationResultsPoVo.setAverageScore2(avgS);
        examinationResultsPoVo.setJudgment(judgment);
        examinationResultsPoVo.setJudgment2(judgment1);
    }

    /**
     * 成绩总统计导出
     * @param examinationResultsComDO
     * @return
     */
    @Override
    public void overallStatisticsDownloadImport(HttpServletResponse response,ExaminationResultsComDO examinationResultsComDO) {
        examinationResultsComDO.setPageSize(9999);
        examinationResultsComDO.setPageNumber(1);
        List<ExaminationResultsVO> records = overallStatistics(examinationResultsComDO.getPageNumber(),examinationResultsComDO.getPageSize()).getRecords();
        //导出操作
        EasyPoiUtil.exportExcel(records, "成绩总统计导出", "成绩总统计导出", ExaminationResultsVO.class, "成绩总统计导出", response);

    }

    /**
     * 成绩公式表导出
     * @param response
     * @param examinationResultsComDO
     */
    @Override
    public void documentWord(HttpServletResponse response, ExaminationResultsComDO examinationResultsComDO) throws Exception {
        examinationResultsComDO.setPageSize(9999);
        examinationResultsComDO.setPageNumber(1);
        List<ExaminationResultsVO> records = overallStatistics(1,999).getRecords();

        //导出组装数据
        Map<String,Object> params =new HashMap<>();
        //暂定
        params.put("batchName","婴幼儿保育");
        List<ExaminationResultsVO> listStu = new ArrayList<>();
        if(records!=null && !records.isEmpty()){
            listStu = records.stream()
                    .filter(vo -> !"-".equals(vo.getTeamScore()) && !"******".equals(vo.getTeamScore()))
                    .sorted((vo1, vo2) -> {
                        try {
                            double score1 = Double.parseDouble(vo1.getTeamScore());
                            double score2 = Double.parseDouble(vo2.getTeamScore());
                            return Double.compare(score2, score1); // 降序排序
                        } catch (NumberFormatException e) {
                            // 处理无法解析的情况，可以决定它们的相对顺序
                            // 这里假设无法解析的字符串应被视为最低分数
                            return 1; // vo1 排在 vo2 后面，实现降序效果
                        }
                    })
                    .collect(Collectors.toList());
            for (int i = 1; i <= listStu.size(); i++) {
                listStu.get(i-1).setSort(i);
            }
        }
        params.put("listStu",listStu);

        XWPFDocument word = WordExportUtil.exportWord07(templateFile().getPath(),params);
        response.setHeader("content-disposition","attachment;filename="+new String("成绩公示表.docx".getBytes(),"ISO8859-1"));
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        word.write(response.getOutputStream());
    }

    //获取docx文件位置
    private File templateFile() throws IOException {

        InputStream inputStream = getClass().getClassLoader().getResourceAsStream("scoreTemplate.docx");
        if (inputStream == null) {
            throw new RuntimeException("Template file not found in resources");
        }

        // 将输入流转换为临时文件
        File tempFile = null;
        try {
            tempFile = File.createTempFile("template", ".docx");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        tempFile.deleteOnExit(); // 在JVM退出时删除临时文件
        Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        return tempFile;
    }

    // 定义安全转换方法，无效或NaN时返回默认值0.0
    private static double safeDoubleParseOrDefault(String value, double defaultValue) {
        try {
            double number = Double.parseDouble(value);
            if (Double.isNaN(number)) {
                return defaultValue; // 如果是NaN，返回默认值
            }
            return number;
        } catch (NumberFormatException e) {
            return defaultValue; // 转换失败时，返回默认值
        }
    }
    /**
     * 各模块得分统计数据
     */
    @Override
    public Result<?> moduleScoreList() {
        ExaminationCostStatisticModuleScoreVo resultVO = new ExaminationCostStatisticModuleScoreVo();
        List<Double> fullList = new ArrayList<>();/** 满分 */
        List<Double> highestList = new ArrayList<>();/** 最高分 */
        List<Double> lowestList = new ArrayList<>();/** 最低分 */
        List<Double> averageList = new ArrayList<>();/** 平均分 */
        List<Double> poorList = new ArrayList<>();/** 分差 */

        //职业素养测评分析
        ExaminationResultsComDO examinationResultsComDO =new ExaminationResultsComDO();
        examinationResultsComDO.setPageNumber(1);
        examinationResultsComDO.setPageSize(9999);
        List<ExaminationResultsPoVo> records = zhiDingStatistics(examinationResultsComDO).getRecords();
//        Optional<ExaminationResultsPoVo> max = records.stream().max(Comparator.comparing(ExaminationResultsPoVo::getAverageScore));
        Optional<ExaminationResultsPoVo> max = records.stream()
                .max(Comparator.comparing(item -> Double.parseDouble(item.getScAverageScore())));
        ExaminationResultsPoVo maxRecords = max.get();
        highestList.add(Double.valueOf(maxRecords.getScAverageScore())); //职业素养测评最高分。
//        Optional<ExaminationResultsPoVo> min = records.stream().min(Comparator.comparing(ExaminationResultsPoVo::getAverageScore));
        Optional<ExaminationResultsPoVo> min = records.stream()
                .min(Comparator.comparing(item -> Double.parseDouble(item.getScAverageScore())));
        ExaminationResultsPoVo minRecords = min.get();
        lowestList.add(Double.valueOf(minRecords.getScAverageScore())); //职业素养测评最低分。
        double totalScore = 0d;
        for (ExaminationResultsPoVo r : records) {
            totalScore += Double.valueOf(r.getScAverageScore());
        }
        averageList.add( totalScore / records.size()); //平均分
        Double difference = Double.valueOf(maxRecords.getScAverageScore()) - Double.valueOf(minRecords.getAverageScore());
        Double result = Math.round(difference * 100.0) / 100.0;
        poorList.add(result); //分差值
//        poorList.add(Double.valueOf(maxRecords.getAverageScore()) - Double.valueOf(minRecords.getAverageScore())); //分差值


        //婴幼儿保育成绩分析
        List<ScResultVO> yyrby = yyrbyStatistics("B1C1", 1, 9999).getRecords();
        List<ScResultVO> yyrby2 = yyrbyStatistics("B2C2", 1, 9999).getRecords();
        List<ScResultVO> yyrby3 = yyrbyStatistics("B3C3", 1, 9999).getRecords();
        List<ScResultVO> yyrby4 = yyrbyStatistics("B4C4", 1, 9999).getRecords();
        yyrby = Stream.of(yyrby, yyrby2, yyrby3, yyrby4)
                .flatMap(List::stream) // 合并所有列表中的元素
                .collect(Collectors.toList());
        Optional<ScResultVO> sMax = yyrby.stream()
                .max(Comparator.comparing(item -> Double.parseDouble(item.getScoreAge1())));
        ScResultVO sMaxRecords = sMax.get();
        highestList.add(Double.valueOf(sMaxRecords.getScoreAge1())); //婴幼儿保育最高分。
        Optional<ScResultVO> sMin = yyrby.stream()
                .min(Comparator.comparing(item -> Double.parseDouble(item.getScoreAge1())));
        ScResultVO sMinRecords = sMin.get();
        lowestList.add(Double.valueOf(sMinRecords.getScoreAge1())); //婴幼儿保育最低分。
        double totalScore1 = 0d;
//        for (ScResultVO r : yyrby) {
//            totalScore1 += Double.valueOf(r.getScoreAge1());
//        }
        for (ScResultVO r : yyrby) {
            double score = safeDoubleParseOrDefault(r.getScoreAge1(), 0.0);
            totalScore1 += score;
        }
        averageList.add( totalScore1 / yyrby.size()); //平均分
        Double difference1 = Double.valueOf(sMaxRecords.getScoreAge1()) - Double.valueOf(sMinRecords.getScoreAge1());
        Double result1 = Math.round(difference1 * 100.0) / 100.0;
        poorList.add(result1); //分差值
//        poorList.add(Double.valueOf(sMaxRecords.getScoreAge1()) - Double.valueOf(sMinRecords.getScoreAge1())); //分差值



        //早期发展学习
        List<ScResultVO> zqfz = zqxxStatistics("B1C1", 1, 9999).getRecords();
        List<ScResultVO> zqfz2 = zqxxStatistics("B2C2", 1, 9999).getRecords();
        List<ScResultVO> zqfz3 = zqxxStatistics("B3C3", 1, 9999).getRecords();
        List<ScResultVO> zqfz4 = zqxxStatistics("B4C4", 1, 9999).getRecords();
        zqfz = Stream.of(zqfz, zqfz2, zqfz3, zqfz4)
                .flatMap(List::stream) // 合并所有列表中的元素
                .collect(Collectors.toList());
        sMax = zqfz.stream()
                .max(Comparator.comparing(item -> Double.parseDouble(item.getScoreAge1())));
        sMaxRecords = sMax.get();
        highestList.add(Double.valueOf(sMaxRecords.getScoreAge1())); //早期发展教育最高分。

        sMin = zqfz.stream()
                .min(Comparator.comparing(item -> Double.parseDouble(item.getScoreAge1())));
        sMinRecords = sMin.get();
        lowestList.add(Double.valueOf(sMinRecords.getScoreAge1())); //早期发展教育最低分。
        double totalScore2 = 0d;
//        for (ScResultVO r : yyrby) {
//            totalScore2 += Double.valueOf(r.getScoreAge1());
//        }
        for (ScResultVO r : yyrby) {
            double score = safeDoubleParseOrDefault(r.getScoreAge1(), 0.0);
            totalScore2 += score;
        }
        averageList.add( totalScore2 / zqfz.size()); //平均分

        Double difference2 = Double.valueOf(sMaxRecords.getScoreAge1()) - Double.valueOf(sMinRecords.getScoreAge1());
        Double result2 = Math.round(difference2 * 100.0) / 100.0;
        poorList.add(result2); //分差值
//        poorList.add(Double.valueOf(sMaxRecords.getScoreAge1()) - Double.valueOf(sMinRecords.getScoreAge1())); //分差值


        fullList.add(30.0);
        fullList.add(40.0);
        fullList.add(30.0);
        resultVO.setFullList(fullList); /** 满分 */
        resultVO.setHighestList(highestList); /** 最高分 */
        resultVO.setLowestList(lowestList); /** 最低分 */
        resultVO.setAverageList(averageList); /** 平均分 */
        resultVO.setPoorList(poorList); /** 分差 */
        return Result.ok(resultVO);
    }

    //获取实操最高、最低、平均、分差
    private void getScoreNums(List<Double> highestList, List<Double> lowestList, List<Double> averageList, List<Double> poorList, List<ExaminationResultsPoVo> listA) {
        double maxScore = Double.parseDouble(Collections.max(listA, Comparator.comparingDouble(poVo->Double.parseDouble(poVo.getAverageScore()))).getAverageScore());
        double minScore = Double.parseDouble(Collections.min(listA, Comparator.comparingDouble(poVo->Double.parseDouble(poVo.getAverageScore()))).getAverageScore());
        double averageScore = Math.round((listA.stream().mapToDouble(poVo->Double.parseDouble(poVo.getAverageScore())).average().orElse(0))* 100.0)/ 100.0;
        getScorePoor(highestList, lowestList, averageList, poorList, maxScore, minScore, averageScore);
    }

    //计算分差
    private void getScorePoor(List<Double> highestList, List<Double> lowestList, List<Double> averageList, List<Double> poorList, double maxScore, double minScore, double averageScore) {
        // 防止精度丢失 将double转换为String，然后再创建BigDecimal对象
        BigDecimal maxDecimal = new BigDecimal(Double.toString(maxScore));
        BigDecimal minDecimal = new BigDecimal(Double.toString(minScore));
        double poor = maxDecimal.subtract(minDecimal).doubleValue();
        highestList.add(maxScore);
        lowestList.add(minScore);
        averageList.add(averageScore);
        poorList.add(poor);
    }

    //获取职业素养测评和制定照护计划最高、最低、平均、分差
    private void getScoreNums2(List<Double> highestList, List<Double> lowestList, List<Double> averageList, List<Double> poorList, List<ExaminationResultsPoVo> list) {
        //计算婴幼儿照护分数（最高、最低、平均、分差）
        double maxScore = Collections.max(list, Comparator.comparingDouble(ExaminationResultsPoVo::getAverageScore1)).getAverageScore1();
        double minScore = Collections.min(list, Comparator.comparingDouble(ExaminationResultsPoVo::getAverageScore1)).getAverageScore1();
        double averageScore = Math.round(list.stream().mapToDouble(ExaminationResultsPoVo::getAverageScore1).average().orElse(0)* 100.0)/ 100.0;
        getScorePoor(highestList, lowestList, averageList, poorList, maxScore, minScore, averageScore);
        //计算产妇照护分数（最高、最低、平均、分差）
        double maxScore2 = Collections.max(list, Comparator.comparingDouble(ExaminationResultsPoVo::getAverageScore2)).getAverageScore2();
        double minScore2 = Collections.min(list, Comparator.comparingDouble(ExaminationResultsPoVo::getAverageScore2)).getAverageScore2();
        double averageScore2 = Math.round(list.stream().mapToDouble(ExaminationResultsPoVo::getAverageScore2).average().orElse(0)* 100.0)/ 100.0;
        getScorePoor(highestList, lowestList, averageList, poorList, maxScore2, minScore2, averageScore2);
    }

    public void addList(List<Double> highestList,List<Double> lowestList,List<Double> averageList,List<Double> poorList){
        highestList.add(0.0);
        lowestList.add(0.0);
        averageList.add(0.0);
        poorList.add(0.0);
    }


    /**
     * 总得分占比
     * @return
     */
    @Override
    public Result<?> totalScoreList() {
        ExaminationCostStatisticTotalScoreVo resultVO = new ExaminationCostStatisticTotalScoreVo();
        List<String> totalScoreList = new ArrayList<>(); /** 总得分占比折线图 */
        List<NationVo> totalScorePercentage = new ArrayList<>(); /** 总得分占比 饼图 */
        List<String> totalScoreXList = new ArrayList<>();
        totalScoreXList.add("0-20分");
        totalScoreXList.add("21-40分");
        totalScoreXList.add("41-60分");
        totalScoreXList.add("61-80分");
        totalScoreXList.add("81-90分");
        totalScoreXList.add("91-100分");

        List<StudentResultsVO> list =new ArrayList<>();
        List<ExaminationResultsVO> records = overallStatistics(1, 9999).getRecords();
        for (int i=0;i<records.size();i++){
            List<StudentResultsVO> studentVOs = records.get(i).getStudentVOs();
            for (int j=0;j<studentVOs.size();j++){
                list.add(studentVOs.get(j));
            }
        }
        // 统计各分数段人数
        int count0to20 = 0;
        int count21to40 = 0;
        int count41to60 = 0;
        int count61to80 = 0;
        int count81to90 = 0;
        int count91to100 = 0;
        for (StudentResultsVO z:list){
            Double tot = Double.valueOf(z.getAScore().equals("-")?"0.0":z.getAScore()) + Double.valueOf(z.getYyrbyScoreZz().equals("-")?"0.0":z.getYyrbyScoreZz()) + Double.valueOf(z.getZqfzScoreZz().equals("-")?"0.0":z.getZqfzScoreZz());
            if (tot >= 0 && tot <= 20) {
                count0to20++;
            } else if (tot >= 21 && tot <= 40) {
                count21to40++;
            } else if (tot >= 41 && tot <= 60) {
                count41to60++;
            } else if (tot >= 61 && tot <= 80) {
                count61to80++;
            } else if (tot >= 81 && tot <= 90) {
                count81to90++;
            }else if (tot >= 91 && tot <= 100) {
                count91to100++;
            }
        }
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count0to20)/Double.valueOf(list.size()))*100)));
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count21to40)/Double.valueOf(list.size()))*100)));
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count41to60)/Double.valueOf(list.size()))*100)));
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count61to80)/Double.valueOf(list.size()))*100)));
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count81to90)/Double.valueOf(list.size()))*100)));
        totalScoreList.add(String.valueOf((int) ((Double.valueOf(count91to100)/Double.valueOf(list.size()))*100)));
        NationVo nationVo = new NationVo();
        nationVo.setName("0-20分");
        nationVo.setValue(String.valueOf((int) ((Double.valueOf(count0to20)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo);
        NationVo nationVo2 = new NationVo();
        nationVo2.setName("21-40分");
        nationVo2.setValue(String.valueOf((int) ((Double.valueOf(count21to40)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo2);
        NationVo nationVo3 = new NationVo();
        nationVo3.setName("41-60分");
        nationVo3.setValue(String.valueOf((int) ((Double.valueOf(count41to60)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo3);
        NationVo nationVo4 = new NationVo();
        nationVo4.setName("61-80分");
        nationVo4.setValue(String.valueOf((int) ((Double.valueOf(count61to80)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo4);
        NationVo nationVo5 = new NationVo();
        nationVo5.setName("81-90分");
        nationVo5.setValue(String.valueOf((int) ((Double.valueOf(count81to90)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo5);
        NationVo nationVo6 = new NationVo();
        nationVo6.setName("91-100分");
        nationVo6.setValue(String.valueOf((int) ((Double.valueOf(count91to100)/Double.valueOf(list.size()))*100)));
        totalScorePercentage.add(nationVo6);

        resultVO.setTotalScoreList(totalScoreList);
        resultVO.setTotalScorePercentage(totalScorePercentage);
        return Result.ok(resultVO);
    }

    /**
     *
     * @param nationVo 分数饼图信息
     * @param nationI 每个区间的分数数量
     * @param total 总分数
     * @param totalScoreList 分数占比折线图
     */
    public void getTotalScoreList(NationVo nationVo,Integer nationI,Integer total,List<String> totalScoreList){
        DecimalFormat df = new DecimalFormat("#.00");
        if(nationI==0){
            totalScoreList.add("0");
            nationVo.setValue("0");
        }else {
            double v = Double.valueOf(nationI) / total;
            String format = df.format(v);
            totalScoreList.add(format);
            nationVo.setValue(format);
        }
    }

    public void getScoreRange(double score,int[] nums){
        if(score<=60){
            nums[0]+=1;
        }else if (score<=70) {
            nums[1]+=1;
        } else if (score<=80) {
            nums[2]+=1;
        } else if (score<=90) {
            nums[3]+=1;
        } else if (score<=100) {
            nums[4]+=1;
        }
    }

    public void addScoreRange(List<Integer> list,int[] nums){
        list.add(nums[0]);
        list.add(nums[1]);
        list.add(nums[2]);
        list.add(nums[3]);
        list.add(nums[4]);
    }

    public int[] createNums(){
        int[] nums = new int[5];
        nums[0] = 0;
        nums[1] = 0;
        nums[2] = 0;
        nums[3] = 0;
        nums[4] = 0;

        return nums;
    }

    /**
     * 百分制分值
     * 制定照护计划满分10分  百分制：10*10
     * 居家场景满分35分     百分制：35*2.85
     * 月子中心场景满分35分  百分制：35*2.85
     * 职业素养测评满分20分  百分制：20*5
     * @return
     */
    @Override
    public Result<?> scoreRangeList() {
        ExaminationCostStatisticScoreRangeVo resultVO = new ExaminationCostStatisticScoreRangeVo();


        List<Integer> zysycpList = new ArrayList<>();/** 职业素养测评折线图 */
        List<Integer> yyrbyjnList = new ArrayList<>();;/** 婴幼儿保育实操折线图 */
        List<Integer> zqxxzcList = new ArrayList<>();;/** 婴幼儿早期学习支持折线图 */


        //职业素养测评分析
        ExaminationResultsComDO examinationResultsComDO =new ExaminationResultsComDO();
        examinationResultsComDO.setPageNumber(1);
        examinationResultsComDO.setPageSize(9999);
        List<ExaminationResultsPoVo> records = zhiDingStatistics(examinationResultsComDO).getRecords();
        for (int i=0;i<records.size();i++){
            records.get(i).setAverageScore( String.valueOf( (Double.valueOf(records.get(i).getAverageScore()) / 30) * 100));
        }
        // 统计各分数段人数
        int count0to60 = 0;
        int count61to70 = 0;
        int count71to80 = 0;
        int count81to90 = 0;
        int count91to100 = 0;
        for (ExaminationResultsPoVo z : records) {
            if (Double.valueOf(z.getAverageScore()) >= 0 && Double.valueOf(z.getAverageScore()) <= 60) {
                count0to60++;
            } else if (Double.valueOf(z.getAverageScore()) >= 61 && Double.valueOf(z.getAverageScore()) <= 70) {
                count61to70++;
            } else if (Double.valueOf(z.getAverageScore()) >= 71 && Double.valueOf(z.getAverageScore()) <= 80) {
                count71to80++;
            } else if (Double.valueOf(z.getAverageScore()) >= 81 && Double.valueOf(z.getAverageScore()) <= 90) {
                count81to90++;
            } else if (Double.valueOf(z.getAverageScore()) >= 91 && Double.valueOf(z.getAverageScore()) <= 100) {
                count91to100++;
            }
        }
        zysycpList.add(count0to60);
        zysycpList.add(count61to70);
        zysycpList.add(count71to80);
        zysycpList.add(count81to90);
        zysycpList.add(count91to100);




        //婴幼儿保育成绩分析
        List<ScResultVO> yyrby = yyrbyStatistics("B1C1", 1, 9999).getRecords();
        List<ScResultVO> yyrby2 = yyrbyStatistics("B2C2", 1, 9999).getRecords();
        List<ScResultVO> yyrby3 = yyrbyStatistics("B3C3", 1, 9999).getRecords();
        List<ScResultVO> yyrby4 = yyrbyStatistics("B4C4", 1, 9999).getRecords();
        yyrby = Stream.of(yyrby, yyrby2, yyrby3, yyrby4)
                .flatMap(List::stream) // 合并所有列表中的元素
                .collect(Collectors.toList());

        for (int i=0;i<yyrby.size();i++){
            yyrby.get(i).setScoreAge1( String.valueOf( (Double.valueOf(yyrby.get(i).getScoreAge1()) / 40) * 100));
        }
        // 统计各分数段人数
        count0to60 = 0;
        count61to70 = 0;
        count71to80 = 0;
        count81to90 = 0;
        count91to100 = 0;

        for (ScResultVO z : yyrby) {
            if (Double.valueOf(z.getScoreAge1()) >= 0 && Double.valueOf(z.getScoreAge1()) <= 60) {
                count0to60++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 61 && Double.valueOf(z.getScoreAge1()) <= 70) {
                count61to70++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 71 && Double.valueOf(z.getScoreAge1()) <= 80) {
                count71to80++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 81 && Double.valueOf(z.getScoreAge1()) <= 90) {
                count81to90++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 91 && Double.valueOf(z.getScoreAge1()) <= 100) {
                count91to100++;
            }
        }
        yyrbyjnList.add(count0to60);
        yyrbyjnList.add(count61to70);
        yyrbyjnList.add(count71to80);
        yyrbyjnList.add(count81to90);
        yyrbyjnList.add(count91to100);




        //早期发展学习
        List<ScResultVO> zqfz = zqxxStatistics("B1C1", 1, 9999).getRecords();
        List<ScResultVO> zqfz2 = zqxxStatistics("B2C2", 1, 9999).getRecords();
        List<ScResultVO> zqfz3 = zqxxStatistics("B3C3", 1, 9999).getRecords();
        List<ScResultVO> zqfz4 = zqxxStatistics("B4C4", 1, 9999).getRecords();
        for (int i=0;i<zqfz.size();i++){
            zqfz.get(i).setScoreAge1( String.valueOf( (Double.valueOf(zqfz.get(i).getScoreAge1()) / 30) * 100));
        }
        zqfz = Stream.of(zqfz, zqfz2, zqfz3, zqfz4)
                .flatMap(List::stream) // 合并所有列表中的元素
                .collect(Collectors.toList());

        // 统计各分数段人数
        count0to60 = 0;
        count61to70 = 0;
        count71to80 = 0;
        count81to90 = 0;
        count91to100 = 0;
        for (ScResultVO z : zqfz) {
            if (Double.valueOf(z.getScoreAge1()) >= 0 && Double.valueOf(z.getScoreAge1()) <= 60) {
                count0to60++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 61 && Double.valueOf(z.getScoreAge1()) <= 70) {
                count61to70++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 71 && Double.valueOf(z.getScoreAge1()) <= 80) {
                count71to80++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 81 && Double.valueOf(z.getScoreAge1()) <= 90) {
                count81to90++;
            } else if (Double.valueOf(z.getScoreAge1()) >= 91 && Double.valueOf(z.getScoreAge1()) <= 100) {
                count91to100++;
            }
        }
        zqxxzcList.add(count0to60);
        zqxxzcList.add(count61to70);
        zqxxzcList.add(count71to80);
        zqxxzcList.add(count81to90);
        zqxxzcList.add(count91to100);


        resultVO.setZysycpList(zysycpList);
        resultVO.setYyrbyjnList(yyrbyjnList);
        resultVO.setZqxxzcList(zqxxzcList);
        return Result.ok(resultVO);
    }

}
